package com.csdj.thread;

import java.util.concurrent.TimeUnit;

public class MoneyThread implements Runnable {

    int balance = 500;

    public synchronized void withdraw(){
        if(balance>=100){
            System.out.println(Thread.currentThread().getName()+"取款100元");
            balance-=100;
            try {
                TimeUnit.MILLISECONDS.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else{
            System.out.println("老子没钱了！");
        }
    }

    @Override
    public void run() {
        for (int i=0;i<5;i++){
            withdraw();
        }

    }
}
